package homework.test;

import java.util.ArrayList;
import java.util.List;

public class MainApp {
    public static void main(String[] args) {
        List<Student> list = new ArrayList<>();//创建集合对象
        list.add(new Student("it001","黄渤", 1.72));
        list.add(new Student("it002","孙红雷", 1.78));
        list.add(new Student("it003","章子怡", 1.64));
        list.add(new Student("it004","杨颖\t", 1.68));
        for (Student student : list) {
            System.out.println(student);
        }
        System.out.println(list.size());
        System.out.println(list.get(2));
        list.remove(3);
        System.out.println(list.size());
        list.set(0,new Student("it005","撒贝宁", 1.67));

        for (Student student : list) {
            if (student.getHeight()>1.7){
                System.out.println(student);
            }
        }
        for (Student student : list) {
            if (student.getName().contains("孙")){
                System.out.println(student);
            }
        }
        int index = 0;
        for (int i = 0; i < list.size()-1; i++) {
            if (list.get(i).getHeight()>list.get(i+1).getHeight()){
                index = i;
            }
        }
        System.out.println(list.get(index));
        System.out.println("------------------------");
        ArrayList<Student> stuList = new ArrayList<>();
        stuList.add(new Student("it001","黄渤", 1.72));
        stuList.add(new Student("it002","孙红雷", 1.78));
        stuList.add(new Student("it003","章子怡", 1.64));

        printAll(stuList);
        findMaxHeight(stuList);

    }

    public static void printAll(ArrayList<Student> stuList){

        for (Student student : stuList) {
            System.out.println(student);
        }

    }
    public static void findMaxHeight(ArrayList<Student> stuList){
        int index = 0;
        for (int i = 0; i < stuList.size()-1; i++) {
            if (stuList.get(i).getHeight()>stuList.get(i+1).getHeight()){
                index = i;
            }
        }
        System.out.println(stuList.get(index));
    }
}
